package com.zm.demo.core.leetcode;

import java.util.Stack;

class MinStack {
    
    Stack<Integer>stack = new Stack<Integer>();
    Stack<Integer>minStack = new Stack<Integer>();
    int min = Integer.MAX_VALUE;
    /** initialize your data structure here. */
    public MinStack() {
        
    }
    
    public void push(int x) {
        min = Math.min(min, x);
        minStack.push(min);
        stack.push(x);
    }
    
    public void pop() {
        stack.pop();
        minStack.pop();
        if (minStack.size() > 0){
            min = minStack.peek();
        }else{
            min = Integer.MAX_VALUE;
        }
    }
    
    public int top() {
        return stack.peek();
    }
    
    public int getMin() {
        return minStack.peek();
    }
}
